package com.ywjh.inter.servlet.data;

import java.awt.font.GlyphJustificationInfo;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ywjh.inter.entity.BloodGlucoseEntity;
import com.ywjh.inter.entity.EquBindEntity;
import com.ywjh.inter.entity.UserPlanTimeEntity;
import com.ywjh.inter.service.EquBindService;
import com.ywjh.inter.service.PatientDataService;
import com.ywjh.inter.service.UsersService;
import com.ywjh.inter.utils.StrUtil;

public class Data extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8577104073573327654L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		float data = StrUtil.getFloat(req.getParameter("data"), 0.0f);
		String sn = req.getParameter("sn");
		Timestamp time = new Timestamp(System.currentTimeMillis());
		int type = 1;
		List<EquBindEntity> list = EquBindService.getInstance().list(sn, type);
		if (!list.isEmpty()) {
			EquBindEntity bind = list.get(0);
			int planId = UsersService.getInstance().getCurrentBgluPlanId(time,bind.getUser_id());
			if(planId!=-1) {
				BloodGlucoseEntity glucoseEntity=new BloodGlucoseEntity();
				glucoseEntity.setAdd_time(time);
				glucoseEntity.setCheck_time(time);
				glucoseEntity.setData(data);
				glucoseEntity.setPlan_id(planId);
				glucoseEntity.setStatus(1);
				glucoseEntity.setUser_id(bind.getUser_id());
				boolean b=PatientDataService.getInstance().addBloodGlucose(glucoseEntity);
			}
		}

	}
}
